package com.efuture.redis;


import redis.clients.jedis.Jedis;

import java.util.Map;
import java.util.Set;

/**
 * @author ：赵山山
 * @description：Jedis操作Hash数据
 * @date ：2021/10/5 9:53 下午
 */
public class JedisOpHash {
    public static void main(String[] args) {

        Jedis jedis = new Jedis();//调用空参构造方法 默认调用本地的redis服务 localhost 6379
        //存值
        jedis.hset("user","username","zhaoshanshan");
        jedis.hset("user","sex","男");
        jedis.hset("user","age","29");
        //遍历
        Map<String, String> user = jedis.hgetAll("user");
        Set<String> keys = user.keySet();
        for(String key :keys){
            //取值
            System.out.println(key+":"+jedis.hget("user",key));
        }
        //删除
        jedis.hdel("user","username");
        jedis.hdel("user","sex");
        jedis.hdel("user","age");
        jedis.close();

    }
}

